<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>文字雨特效</title>
  <link rel="stylesheet" href="style.css">
</head>

<body>
  <div class="container">
    <div class="cloud">
      <h2>Data Clouds Rain</h2>
    </div>
  </div>
</body>
<script>
  function randomText() {
    const text = ("abcdefghjklmnopqrstuvwsyz1234567890~!@#$%^&*()_+")
    letters = text[Math.floor(Math.random() * text.length)]
    return letters
  }

  function rain() {
    let cloud = document.querySelector('.cloud')
    let e = document.createElement('div')

    e.classList.add('drop')
    cloud.appendChild(e)

    let left = Math.floor(Math.random() * 300)
    let size = Math.random() * 1.5
    let duration = Math.random() * 1

    e.innerText = randomText()
    e.style.left = left + 'px'
    e.style.fontSize = 0.5 + size + 'em'
    e.style.animationDirection = 1 + duration + 's'

    setTimeout(() => {
      cloud.removeChild(e)
    }, 2000)
  }

  setInterval(() => {
    rain()
  }, 20)
</script>

</html>